﻿using System;
using System.Collections.Generic;
using EXT;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;

namespace BanHangCshap.BaoCaoTongHop
{
    public partial class frmTonghopThuchi : Form
    {
        public frmTonghopThuchi()
        {
            InitializeComponent();
        }

        private void frmTonghopThuchi_Load(object sender, EventArgs e)
        {
            dtpDenngay.EditValue = DateTime.Now;
            dtpTungay.EditValue = SDN.LayNgaydauthang();
        }

        Class.gkhtdl63.BLL.AllInOneBLL xgAllInOneBLL = new BanHangCshap.Class.gkhtdl63.BLL.AllInOneBLL();
        DataTable xgDT = new DataTable();

        private void btnXem_Click(object sender, EventArgs e)
        {
            xgDT = xgAllInOneBLL.TonghopThuchi(dtpTungay.EditValue, dtpDenngay.EditValue);
            if (xgDT!=null)
            {
                if (xgDT.Rows.Count>0)
                {
                    int C = xgDT.Rows.Count - 1;
                    decimal Thu = 0;
                    decimal Chi = 0;
                    for (int i = 0; i < C; i++)
                    {
                        if (xgDT.Rows[i]["Loai"].ToString().Equals("Thu"))
                        {
                            Thu += xgDT.Rows[i]["Sotien"].ToDecimal();
                        }
                        else Chi += xgDT.Rows[i]["Sotien"].ToDecimal();
                    }
                    txtCondu.EditValue = "Số tiền còn dư: " + (Thu - Chi).ToString("n0");
                    txtTienchu.Text = (Thu - Chi).ToString().ToVietnamese().ToUpperFirst() + " VNĐ.";
                }
            }
            grcKetQuaKinhDoanh.DataSource = xgDT;
        }

        private void btnXemIn_Click(object sender, EventArgs e)
        {
            WaitDialogForm dg = new WaitDialogForm("Đang load dữ liệu...", "Xin chờ trong giây lát.");
            Report.gkhtdl63.frmMainRPTS frm = new BanHangCshap.Report.gkhtdl63.frmMainRPTS();
            Report.gkhtdl63.MyRPT.Thongke.rptTonghopThuchi rpt = new BanHangCshap.Report.gkhtdl63.MyRPT.Thongke.rptTonghopThuchi(txtCondu.Text, "Bằng chử: " + txtTienchu.Text, "Từ ngày " + dtpTungay.Text + " đến ngày " + dtpDenngay.Text);
            rpt.DataSource = xgDT;
            frm.SetReport(rpt);
            dg.Close();
            frm.ShowDialog();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
